<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>修改学生信息</title>
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript">
        $(function () {
            $.get("/student/findOne?id=" + getParameter("id"), function (student) {
                if (student) {
                    for (let studentKey in student) {
                        // console.log(studentKey+":"+student[studentKey]);
                        id = "#" + studentKey;
                        $(id).val(student[studentKey]);
                    }
                }
            });

            $("#editForm").submit(function () {
                $.post("/student/edit", $(this).serialize(), function (data) {
                    if (data === true) {
                        if(confirm("修改成功！返回首页")){
                            location.href = "/index.html";
                        }
                    } else {
                        alert("修改失败")
                    }
                });
                return false;
            });
        });
    </script>
</head>
<body>
<form id="editForm">
    <table>
        <tr>
            <td></td>
            <td><input type="hidden" id="id" name="id" value=""/></td>
            <td></td>
        </tr>
        <tr>
            <td> 姓名:</td>
            <td><input name="name" id="name" type="text" value=""></td>
            <td></td>
        </tr>
        <tr>
            <td> 密码:</td>
            <td><input name="password" id="password" type="password" value=""></td>
            <td></td>
        </tr>
        <tr>
            <td> 年龄:</td>
            <td><input name="age" id="age" type="text" value=""></td>
            <td></td>
        </tr>
        <tr>
            <td> 性别:</td>
            <td><input name="sex" id="sex" type="text" value=""></td>
            <td></td>
        </tr>
        <tr>
            <td> 生日:</td>
            <td><input name="birthday" id="birthday" type="date"
                       value=<fmt:formatDate value='' pattern='yyyy-MM-dd'/>
            </td>
            <td></td>
        </tr>
        <tr>
            <td> 地址:</td>
            <td><input name="address" id="address" type="text" value=""></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="修改"></td>
            <td><a href="javascript:history.go(-1)">返回</a> </td>
        </tr>
    </table>
</form>
</body>
</html>